﻿using System;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

// Token: 0x020003A0 RID: 928
public class DragInputUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler, IEventSystemHandler
{
	// Token: 0x1700023C RID: 572
	// (get) Token: 0x06001712 RID: 5906 RVA: 0x0009AF28 File Offset: 0x00099128
	// (set) Token: 0x06001713 RID: 5907 RVA: 0x0009AF30 File Offset: 0x00099130
	public bool IsDragging { get; protected set; }

	// Token: 0x06001714 RID: 5908 RVA: 0x0009AF3C File Offset: 0x0009913C
	private void Awake()
	{
		this.myRect = base.GetComponent<RectTransform>();
	}

	// Token: 0x06001715 RID: 5909 RVA: 0x0009AF4C File Offset: 0x0009914C
	private void Update()
	{
		if (this.IsDragging)
		{
			this.UpdateDrag();
		}
	}

	// Token: 0x06001716 RID: 5910 RVA: 0x0009AF60 File Offset: 0x00099160
	public void AddListener(UnityAction<Vector2> call)
	{
		this.onDragEvent.AddListener(call);
	}

	// Token: 0x06001717 RID: 5911 RVA: 0x0009AF70 File Offset: 0x00099170
	public void OnBeginDrag(PointerEventData data)
	{
		this.IsDragging = true;
		GameCursor.Lock();
	}

	// Token: 0x06001718 RID: 5912 RVA: 0x0009AF80 File Offset: 0x00099180
	public void OnDrag(PointerEventData data)
	{
		this.IsDragging = true;
	}

	// Token: 0x06001719 RID: 5913 RVA: 0x0009AF8C File Offset: 0x0009918C
	private void UpdateDrag()
	{
		GameCursor.Lock();
		Vector2 arg = Vector3.zero;
		arg.x = Input.GetAxis("Mouse X");
		arg.y = Input.GetAxis("Mouse Y");
		this.CheckMoveArea(ref arg);
		if (this.onDragEvent != null)
		{
			this.onDragEvent.Invoke(arg);
		}
	}

	// Token: 0x0600171A RID: 5914 RVA: 0x0009AFEC File Offset: 0x000991EC
	public void OnEndDrag(PointerEventData data)
	{
		this.IsDragging = false;
	}

	// Token: 0x0600171B RID: 5915 RVA: 0x0009AFF8 File Offset: 0x000991F8
	private void CheckMoveArea(ref Vector2 move)
	{
		Vector2 a = this.myRect.position;
		Vector2 vector = a + this.myRect.rect.min + move;
		Vector2 vector2 = a + this.myRect.rect.max + move;
		Vector2 zero = Vector2.zero;
		if (vector.x < 0f)
		{
			zero.x = -vector.x;
		}
		if (vector.y < 0f)
		{
			zero.y = -vector.y;
		}
		if (vector2.x > (float)Screen.width)
		{
			zero.x = (float)Screen.width - vector2.x;
		}
		if (vector2.y > (float)Screen.height)
		{
			zero.y = (float)Screen.height - vector2.y;
		}
		move += zero;
	}

	// Token: 0x04001ADE RID: 6878
	private RectTransform myRect;

	// Token: 0x04001ADF RID: 6879
	public DragInputUI.DragEvent onDragEvent;

	// Token: 0x020003A1 RID: 929
	[Serializable]
	public class DragEvent : UnityEvent<Vector2>
	{
	}
}
